package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatContentGodHelp;
import com.happy.cat.project.system.service.ICatContentGodHelpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 大神帮助Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/contentHelp" )
@Api("大神帮助 API")
public class CatContentGodHelpController extends BaseController {

    private final ICatContentGodHelpService iCatContentGodHelpService;

    /**
     * 查询大神帮助列表
     */
    @ApiOperation(value = "查询大神帮助列表",notes = "查询大神帮助列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatContentGodHelp catContentGodHelp)
    {
        startPage();
        LambdaQueryWrapper<CatContentGodHelp> lqw = new LambdaQueryWrapper<CatContentGodHelp>();
        if (StringUtils.isNotBlank(catContentGodHelp.getName())){
            lqw.like(CatContentGodHelp::getName ,catContentGodHelp.getName());
        }
        if (catContentGodHelp.getIsShow() != null){
            lqw.eq(CatContentGodHelp::getIsShow ,catContentGodHelp.getIsShow());
        }
        if (StringUtils.isNotBlank(catContentGodHelp.getIcon())){
            lqw.eq(CatContentGodHelp::getIcon ,catContentGodHelp.getIcon());
        }
        if (StringUtils.isNotBlank(catContentGodHelp.getContent())){
            lqw.eq(CatContentGodHelp::getContent ,catContentGodHelp.getContent());
        }
        if (catContentGodHelp.getSortId() != null){
            lqw.eq(CatContentGodHelp::getSortId ,catContentGodHelp.getSortId());
        }
        if (catContentGodHelp.getCreateDate() != null){
            lqw.eq(CatContentGodHelp::getCreateDate ,catContentGodHelp.getCreateDate());
        }
        if (catContentGodHelp.getStatus() != null){
            lqw.eq(CatContentGodHelp::getStatus ,catContentGodHelp.getStatus());
        }
        List<CatContentGodHelp> list = iCatContentGodHelpService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出大神帮助列表
     */
    @ApiOperation(value = "导出大神帮助列表",notes = "导出大神帮助列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:export')" )
    @Log(title = "大神帮助" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatContentGodHelp catContentGodHelp) {
        LambdaQueryWrapper<CatContentGodHelp> lqw = new LambdaQueryWrapper<CatContentGodHelp>(catContentGodHelp);
        List<CatContentGodHelp> list = iCatContentGodHelpService.list(lqw);
        ExcelUtil<CatContentGodHelp> util = new ExcelUtil<CatContentGodHelp>(CatContentGodHelp. class);
        return util.exportExcel(list, "contentHelp" );
    }

    /**
     * 获取大神帮助详细信息
     */
    @ApiOperation(value = "获取大神帮助详细信息",notes = "获取大神帮助详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatContentGodHelpService.getById(id));
    }

    /**
     * 新增大神帮助
     */
    @ApiOperation(value = "新增大神帮助",notes = "新增大神帮助",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:add')" )
    @Log(title = "大神帮助" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatContentGodHelp catContentGodHelp) {
        catContentGodHelp.setCreateDate(new Date());
        catContentGodHelp.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatContentGodHelpService.save(catContentGodHelp) ? 1 : 0);
    }

    /**
     * 修改大神帮助
     */
    @ApiOperation(value = "修改大神帮助",notes = "修改大神帮助",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:edit')" )
    @Log(title = "大神帮助" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatContentGodHelp catContentGodHelp) {
        catContentGodHelp.setCreateDate(new Date());
        catContentGodHelp.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatContentGodHelpService.updateById(catContentGodHelp) ? 1 : 0);
    }

    /**
     * 删除大神帮助
     */
    @ApiOperation(value = "删除大神帮助",notes = "删除大神帮助",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:contentHelp:remove')" )
    @Log(title = "大神帮助" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatContentGodHelpService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
